package com.pdsu.graduation_design.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.pdsu.graduation_design.R;
import com.pdsu.graduation_design.dto.PayCommodityDTO;
import com.squareup.picasso.Picasso;

import java.util.List;

public class OrderListViewAdapter extends BaseAdapter {

    private Context context;
    private List<PayCommodityDTO> commodityList;
    private ImageView imageView_icon;
    private TextView commodityName,commodityPrice,commodityNumber;

    public OrderListViewAdapter(Context context, List<PayCommodityDTO> commodityList) {
        this.context = context;
        this.commodityList = commodityList;
    }

    @Override
    public int getCount() {
        return commodityList.size();
    }

    @Override
    public Object getItem(int position) {
        return commodityList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view=View.inflate(context, R.layout.order_listview_item,null);

        imageView_icon=view.findViewById(R.id.order_listview_image);
        commodityName=view.findViewById(R.id.order_listview_title);
        commodityNumber=view.findViewById(R.id.order_listview_number);
        commodityPrice=view.findViewById(R.id.order_listview_price);

        commodityPrice.setText(commodityList.get(position).getPrice()+"");
        commodityNumber.setText(commodityList.get(position).getUcnumber()+"");
        commodityName.setText(commodityList.get(position).getCname());

        Picasso.with(context).load(commodityList.get(position).getImage()).into(imageView_icon);


        return view;
    }
}
